export default class MathUtil {
    static randomRangeFloat(start: number, end: number) {
        return start + Math.random() * (end - start);
    }

    static randomRangeInt(start: number, end: number) {
        return Math.floor(start + Math.random() * (end - start));
    }

    static calcBezierControlPoints(start: cc.Vec2, end: cc.Vec2, offset: cc.Vec2) {
        let pointsRatios = [.3, .7];
        let point0 = cc.v2();// top point
        cc.Vec2.lerp(point0, start, end, pointsRatios[0]);
        point0.addSelf(offset);
        let point1 = cc.v2();
        cc.Vec2.lerp(point1, start, end, pointsRatios[1]);
        point1.addSelf(offset.mulSelf(pointsRatios[0]));
        return [point0, point1];
    }

    static randomUuid(len: number) {
        let patterns = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        let str = "";
        for (let i = 0; i < len; i++) {
            str += patterns.charAt(this.randomRangeInt(0, patterns.length));
        }
        return str;
    }

    static randomScreenPos() {// center point is 0,0
        return cc.v2(this.randomRangeFloat(-cc.winSize.width * .5, cc.winSize.width * .5),
            this.randomRangeFloat(-cc.winSize.height * .5, cc.winSize.height * .5))
    }
}